from PIL import ImageGrab
from selenium import webdriver

class goods_order:
    def __init__(self,wd):
        self.wd = wd
        # self.wd = webdriver.Firefox()
        # self.wd.get("http:172.16.0.105/TinyShop_v2.4/index.php/admin")
        # self.wd.implicitly_wait(10)
    def login(self):
        self.wd.find_element_by_xpath('/html/body/div/div/form/ul/li[1]/input').send_keys('admin')
        self.wd.find_element_by_xpath('/html/body/div/div/form/ul/li[2]/input').send_keys('123456')
        self.wd.find_element_by_xpath('/html/body/div/div/form/ul/li[3]/input').send_keys('aaaa')
        self.wd.find_element_by_xpath('//li[4]/input').click()
    def goods(self,number,img):
        # 进入商品订单操作
        self.login()
        self.wd.find_element_by_link_text('订单中心').click()
        self.wd.find_element_by_link_text('处理').click()
        self.wd.find_element_by_link_text('发货').click()
        # 切换焦点至iframe
        self.wd.switch_to.frame(self.wd.find_element_by_xpath('/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div/iframe'))
        self.wd.find_element_by_xpath('//td[2]/input').send_keys(number)
        self.wd.find_element_by_xpath('/html/body/div/form/div/button').click()
        self.wd.switch_to_default_content()

        im = ImageGrab.grab()
        im.save(r'C:\Users\Administrator\Desktop\caseall\pic\%s.jpg'%(img))

        self.wd.quit()



# goods_order().goods()
